#include <string.h>
#include <stdio.h>

/*
 * 结构体在编译期间被删除了		P162
 */

struct zzz
{
	char s[16];
	int a;
	float f;
};

/* 有意地展示了通过隐含地生成局部变量来进行结构体的传递 */
void func(struct zzz y)
{
	printf("%s %x %f.\n", &y.s[0], y.a, y.f);
}

int main()
{
	struct zzz y;
	
	strcpy(&y.s[0], "Hello, xiaozhi!");
	y.a = 0x666;
	y.f = 6.6;
	func(y);
}

/*
	Hello, xiaozhi! 666 6.600000.
 */

#if 0

1.将字符串拆解为整型常量，然后赋值到栈空间上

/*
 * intel
 */
0000000000001169 <func>:	// 0x0000555555555169
    1169:	f3 0f 1e fa          	endbr64						// (rsp=0x7fffffffe068)=0x00005555555551f7, rbp=0x7fffffffe0b0
    116d:	55                   	push   %rbp					// rsp=0x7fffffffe060, rbp=0x7fffffffe0b0
    116e:	48 89 e5             	mov    %rsp,%rbp			// rsp=0x7fffffffe060, rbp=0x7fffffffe060
    1171:	f3 0f 10 45 24       	movss  0x24(%rbp),%xmm0		// rbp+0x24=0x7fffffffe084: 0x5555522040d33333; rbp+0x20=0x7fffffffe080: 0x40d3333300000666; {v4_float = {6.5999999, 0, 0, 0}, v2_double = {5.3733741064073288e-315, 0}
    1176:	f3 0f 5a c0          	cvtss2sd %xmm0,%xmm0		// {v4_float = {3.68934881e+19, 2.4124999, 0, 0}, v2_double = {6.5999999046325684, 0}
    117a:	8b 45 20             	mov    0x20(%rbp),%eax		// rbp+0x20=0x7fffffffe080: 0x40d3333300000666, eax=0x666
    117d:	89 c2                	mov    %eax,%edx			// edx=0x666
    117f:	48 8d 75 10          	lea    0x10(%rbp),%rsi		// rsi=0x7fffffffe070: 0x78202c6f6c6c6548
    1183:	48 8d 3d 7a 0e 00 00 	lea    0xe7a(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> // rdi=0x555555556004: 0x6625207825207325="%s %x %f"
    118a:	b8 01 00 00 00       	mov    $0x1,%eax			// eax=1
    118f:	e8 dc fe ff ff       	callq  1070 <printf@plt>	// printf(rdi, rsi, edx, xmm0)
    1194:	90                   	nop
    1195:	5d                   	pop    %rbp					// rsp=0x7fffffffe068, rbp=0x7fffffffe0b0
    1196:	c3                   	retq   

0000000000001197 <main>:	// 0x0000555555555197
    1197:	f3 0f 1e fa          	endbr64 
    119b:	55                   	push   %rbp					// rsp=0x7fffffffe0b8, rbp = (void *) 0x0  ===> 0x7fffffffe0b0=0x0
    119c:	48 89 e5             	mov    %rsp,%rbp			// rsp=0x7fffffffe0b0, rbp = 0x7fffffffe0b0
    119f:	48 83 ec 20          	sub    $0x20,%rsp			// rsp=0x7fffffffe090, rbp = 0x7fffffffe0b0
    11a3:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax		// rsp=0x7fffffffe090, rbp = 0x7fffffffe0b0, rax=0xbd905bac7068ca00
    11aa:	00 00 
    11ac:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-8=0x7fffffffe0a8, 0x7fffffffe0a8: 0xbd905bac7068ca00
    11b0:	31 c0                	xor    %eax,%eax			// 0x7068ca00
    11b2:	48 8d 45 e0          	lea    -0x20(%rbp),%rax		// rax=0x7fffffffe090
    11b6:	48 ba 48 65 6c 6c 6f 	movabs $0x78202c6f6c6c6548,%rdx	// rdx=0x78202c6f6c6c6548
    11bd:	2c 20 78 
    11c0:	48 b9 69 61 6f 7a 68 	movabs $0x2169687a6f6169,%rcx	// rcx=0x2169687a6f6169
    11c7:	69 21 00												// rax=0x7fffffffe090: 0x0000000000000000
    11ca:	48 89 10             	mov    %rdx,(%rax)				// rax=0x7fffffffe090: 0x78202c6f6c6c6548
    11cd:	48 89 48 08          	mov    %rcx,0x8(%rax)			// rax+8=0x7fffffffe098: 0x002169687a6f6169
    11d1:	c7 45 f0 66 06 00 00 	movl   $0x666,-0x10(%rbp)		// rbp-0x10=0x7fffffffe0a0: 0x00007fff00000666
    11d8:	f3 0f 10 05 30 0e 00 	movss  0xe30(%rip),%xmm0        # 2010 <_IO_stdin_used+0x10>	// 0x40d33333=6.599999904632568
    11df:	00													// rip+0xe30=0x5555555551e0+0xe30=0x555555556010: 0x3b031b0140d33333
    11e0:	f3 0f 11 45 f4       	movss  %xmm0,-0xc(%rbp)		// rbp-0xc=0x7fffffffe0a4: 0x7068ca0040d33333
    11e5:	48 83 ec 08          	sub    $0x8,%rsp			// rsp=0x7fffffffe088, rbp=0x7fffffffe0b0
    11e9:	ff 75 f0             	pushq  -0x10(%rbp)			// rsp=0x7fffffffe080:0x40d3333300000666, rbp-0x10=0x7fffffffe0a0: 0x40d3333300000666 # 压的是-0x10(%rbp)地址上的值。
    11ec:	ff 75 e8             	pushq  -0x18(%rbp)			// rsp=0x7fffffffe078:0x002169687a6f6169, rbp-0x18=0x7fffffffe098: 0x002169687a6f6169
    11ef:	ff 75 e0             	pushq  -0x20(%rbp)			// rsp=0x7fffffffe070:0x78202c6f6c6c6548, rbp-0x20=0x7fffffffe090: 0x78202c6f6c6c6548
    11f2:	e8 72 ff ff ff       	callq  1169 <func>
    11f7:	48 83 c4 20          	add    $0x20,%rsp	# 0x00005555555551f7 		
    11fb:	b8 00 00 00 00       	mov    $0x0,%eax
    1200:	48 8b 75 f8          	mov    -0x8(%rbp),%rsi
    1204:	64 48 33 34 25 28 00 	xor    %fs:0x28,%rsi
    120b:	00 00 
    120d:	74 05                	je     1214 <main+0x7d>
    120f:	e8 4c fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    1214:	c9                   	leaveq 
    1215:	c3                   	retq   
    1216:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    121d:	00 00 00 



0000000000001169 <func>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	f3 0f 10 45 24       	movss  0x24(%rbp),%xmm0		// xmm0=rbp+0x24 将一个单精度数传输到xmm寄存器的低32位
    1176:	f3 0f 5a c0          	cvtss2sd %xmm0,%xmm0		// 把源存储器低32位1个单精度浮点数变成1个双精度浮点数,
																// 结果送入目的寄存器的低64位,高64位不变.
    117a:	8b 45 20             	mov    0x20(%rbp),%eax		// eax=rbp+0x20
    117d:	89 c2                	mov    %eax,%edx			// edx=eax
    117f:	48 8d 75 10          	lea    0x10(%rbp),%rsi		// rsi=rbp+0x10
    1183:	48 8d 3d 7a 0e 00 00 	lea    0xe7a(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>  rdi=rip+0xe7a
    118a:	b8 01 00 00 00       	mov    $0x1,%eax			// eax=1
    118f:	e8 dc fe ff ff       	callq  1070 <printf@plt>	// printf(rdi,rsi,edx,xmm0) 
    1194:	90                   	nop
    1195:	5d                   	pop    %rbp
    1196:	c3                   	retq   

0000000000001197 <main>:
    1197:	f3 0f 1e fa          	endbr64 
    119b:	55                   	push   %rbp
    119c:	48 89 e5             	mov    %rsp,%rbp
    119f:	48 83 ec 20          	sub    $0x20,%rsp
    11a3:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11aa:	00 00 
    11ac:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-0x8=rax=fs:0x28
    11b0:	31 c0                	xor    %eax,%eax			// eax=0
    11b2:	48 8d 45 e0          	lea    -0x20(%rbp),%rax		// rax=rbp-0x20
    11b6:	48 ba 48 65 6c 6c 6f 	movabs $0x78202c6f6c6c6548,%rdx	// rdx=0x78202c6f6c6c6548="x ,olleH"
    11bd:	2c 20 78 
    11c0:	48 b9 69 61 6f 7a 68 	movabs $0x2169687a6f6169,%rcx	// rcx=0x2169687a6f6169="!ihzoai"
    11c7:	69 21 00 
    11ca:	48 89 10             	mov    %rdx,(%rax)		// (rax)=rdx  ==> (rbp-0x20)=rdx=0x78202c6f6c6c6548
    11cd:	48 89 48 08          	mov    %rcx,0x8(%rax)		// rax+0x8=rcx ==> (rbp-0x20+0x8)=(rbp-0x18)=rcx
    11d1:	c7 45 f0 66 06 00 00 	movl   $0x666,-0x10(%rbp)	// rbp-0x10=0x666
    11d8:	f3 0f 10 05 30 0e 00 	movss  0xe30(%rip),%xmm0        # 2010 <_IO_stdin_used+0x10> 将一个单精度数传输到xmm寄存器的低32位
    11df:	00 
    11e0:	f3 0f 11 45 f4       	movss  %xmm0,-0xc(%rbp)		// rbp-0xc=xmm0=6.6 将一个单精度数传输到xmm寄存器的低32位
    11e5:	48 83 ec 08          	sub    $0x8,%rsp		// rsp-=0x8
    11e9:	ff 75 f0             	pushq  -0x10(%rbp)		// rbp-0x10 = 0x666
    11ec:	ff 75 e8             	pushq  -0x18(%rbp)		// rbp-0x18 = 0x2169687a6f6169
    11ef:	ff 75 e0             	pushq  -0x20(%rbp)		// rbp-0x20 = 0x78202c6f6c6c6548
    11f2:	e8 72 ff ff ff       	callq  1169 <func>		// func(rbp-0x20)
    11f7:	48 83 c4 20          	add    $0x20,%rsp		// rsp+=0x20
    11fb:	b8 00 00 00 00       	mov    $0x0,%eax		// eax=0
    1200:	48 8b 75 f8          	mov    -0x8(%rbp),%rsi		// rsi=rbp-0x8=fs:0x28
    1204:	64 48 33 34 25 28 00 	xor    %fs:0x28,%rsi
    120b:	00 00 
    120d:	74 05                	je     1214 <main+0x7d>
    120f:	e8 4c fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    1214:	c9                   	leaveq 
    1215:	c3                   	retq   
    1216:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    121d:	00 00 00 

/*
 * arm
 */
000000000040055c <func>:
  40055c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400560:	910003fd 	mov	x29, sp
  400564:	f9000bf3 	str	x19, [sp, #16]		// sp+16=x19
  400568:	aa0003f3 	mov	x19, x0			// x19=x0
  40056c:	b9401261 	ldr	w1, [x19, #16]		// w1=x19+16
  400570:	bd401660 	ldr	s0, [x19, #20]		// s0=x19+20
  400574:	1e22c000 	fcvt	d0, s0
  400578:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  40057c:	911ac000 	add	x0, x0, #0x6b0		// x0
  400580:	2a0103e2 	mov	w2, w1			// w2=w1
  400584:	aa1303e1 	mov	x1, x19			// x1=x19
  400588:	97ffffb2 	bl	400450 <printf@plt>	// printf()
  40058c:	d503201f 	nop
  400590:	f9400bf3 	ldr	x19, [sp, #16]
  400594:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400598:	d65f03c0 	ret

000000000040059c <main>:
  40059c:	a9bb7bfd 	stp	x29, x30, [sp, #-80]!
  4005a0:	910003fd 	mov	x29, sp
  4005a4:	9100e3a2 	add	x2, x29, #0x38			// x2=x29+0x38
  4005a8:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005ac:	911b0000 	add	x0, x0, #0x6c0			// x0=4006c0
  4005b0:	a9400400 	ldp	x0, x1, [x0]			// x0=[x0], x1=[x0+8]
  4005b4:	a9000440 	stp	x0, x1, [x2]			// [x2]=x0, [x2+8]=x1
  4005b8:	5280ccc0 	mov	w0, #0x666                 	// #1638
  4005bc:	b9004ba0 	str	w0, [x29, #72]			// x29+72=w0
  4005c0:	52866660 	mov	w0, #0x3333                	// #13107
  4005c4:	72a81a60 	movk	w0, #0x40d3, lsl #16
  4005c8:	1e270000 	fmov	s0, w0				// s0=w0
  4005cc:	bd004fa0 	str	s0, [x29, #76]			// x29+76=s0
  4005d0:	910043a2 	add	x2, x29, #0x10			// x2=x29+0x10
  4005d4:	9100e3a3 	add	x3, x29, #0x38			// x3=x29+0x38
  4005d8:	a9400460 	ldp	x0, x1, [x3]			// x0=x3, x1=x3+8
  4005dc:	a9000440 	stp	x0, x1, [x2]			// x2=x0, x2+8=x1
  4005e0:	f9400860 	ldr	x0, [x3, #16]			// x0=x3+16
  4005e4:	f9000840 	str	x0, [x2, #16]			// x2+16=x0
  4005e8:	910043a0 	add	x0, x29, #0x10			// x0=x29+0x10
  4005ec:	97ffffdc 	bl	40055c <func>			// func()
  4005f0:	52800000 	mov	w0, #0x0                   	// #0
  4005f4:	a8c57bfd 	ldp	x29, x30, [sp], #80
  4005f8:	d65f03c0 	ret
  4005fc:	00000000 	.inst	0x00000000 ; undefined


 #endif
